// 输入两个单调递增的链表，输出两个链表合成后的链表，当然我们需要合成后的链表满足单调不减规则。
import {node,nodeList} from './nodeList'

function Merge(pHead1, pHead2) {
  // write code here
    let head=new nodeList(null)
    let flag=head
    while(pHead1&&pHead2){
        if(pHead1.val<=pHead2.val){
            head.next=pHead1
            pHead1=pHead1.next
        }else{
            head.next=pHead2
            pHead2=pHead2.next
        }
        head=head.next
    }
    if(!pHead1){
        head.next=pHead2
    }
    if(!pHead2){
        head.next=pHead1
    }
    return flag.next
}//迭代版本
function Merge(pHead1, pHead2){
    if(!pHead1)return pHead2
    if(!pHead2)return pHead1
    let head=new node(null)
    if(pHead1.val<=pHead2.val){
        head.next=pHead1
        pHead1=pHead1.next
    }else{
        head.next=pHead2
        pHead2=pHead2.next
    }
    head.next.next=Merge(pHead1,pHead2)
    return head.next
}//递归版本